from mysqldb.main import *

from .FilterBackends import *


class NewGamePlacetokenListSerializer(serializers.Serializer):
    """注册"""

    pid = IntegerField(required=True, help_text="场所PID")

    class Meta:
        fields = "__all__"

    def validate_pid(self, attr):
        try:
            AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在或停用")
        # 数据是否存在
        if GamePlacetokenList.objects.filter(id=attr).exists():
            raise serializers.ValidationError("该场所账户已存在")
        return attr


class LoadGameConfListSerializer(serializers.Serializer):
    """登录"""

    appid = CharField(
        help_text="appid",
    )
    secret = CharField(
        help_text="secret",
    )

    class Meta:
        fields = "__all__"


class GamePlacetokenListSerializer(serializers.ModelSerializer):
    """游戏活动配置账号"""

    class Meta:
        model = GamePlacetokenList
        fields = "__all__"


class GamePlaceconfLolBaseSerializer(serializers.ModelSerializer):
    """LOL基本配置"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolBase.objects.all())],
        help_text="场所ID",
    )
    long = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 10,
        required=True,
        help_text="配置数据",
    )
    # long = ChoiceField(choices=("有效", "无效", "仅时长"), help_text="在线时长送红包同时有效")
    # dostaff = ChoiceField(choices=("允许", "禁止"), help_text="员工能否参加活动")
    # dowin = ChoiceField(choices=("只赢有", "输也有", "只输有"), help_text="只有赢才有红包")
    # status = IntegerField(default=0, help_text="状态 1:启用 0:停用")
    # firstwin = IntegerField(max_value=1, min_value=0, default=0, help_text="首胜奖励方式")
    # barfirstwinspeed = IntegerField(default=0, help_text="网吧首胜奖励乘此系数(%)")
    # lolfirstwinspeed = IntegerField(default=0, help_text="腾讯首胜奖励乘此系数(%)")
    # maxred = IntegerField(default=0, help_text="红包最多个数(天)")
    # minshare = IntegerField(default=0, help_text="微信分享领取红包最小金额(分)")
    # doshare = IntegerField(max_value=1, min_value=0, default=0, help_text="强制分享")
    # dolook = IntegerField(default=0, help_text="分享后关注")
    # donewvip = IntegerField(default=0, help_text="分享后到店成会员(新会员)")
    # dooldvip = IntegerField(default=0, help_text="分享后到店成会员(老会员)")
    # toparent = IntegerField(default=0, help_text="新会员战绩红包同时奖励老会员(%)")
    # barwin = IntegerField(max_value=1, min_value=0, default=0, help_text="网吧胜场奖励")
    # lolwin = IntegerField(max_value=1, min_value=0, default=0, help_text="腾讯胜场奖励")
    # tasks = IntegerField(max_value=1, min_value=0, default=0, help_text="任务奖励")

    class Meta:
        model = GamePlaceconfLolBase
        fields = ["id", "pid", "long"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


# print(repr(GamePlaceconfLolBaseSerializer()))


class GamePlaceconfLolLevelSerializer(serializers.ModelSerializer):
    """LOL段位配置"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolLevel.objects.all())],
        help_text="场所ID",
    )
    level = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 10,
        required=True,
        help_text="配置数据",
    )
    # level = ChoiceField(
    #     choices=("菜鸟", "黑铁", "白银", "黄铜", "黄金", "铂金", "钻石", "超凡大师", "傲世宗师", "最强王者"),
    #     help_text="段位名称",
    # )
    # care = IntegerField(default=0, help_text="系数")

    class Meta:
        model = GamePlaceconfLolLevel
        fields = ["id", "pid", "level"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


class GamePlaceconfLolTypesSerializer(serializers.ModelSerializer):
    """LOL赛制配置"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolTypes.objects.all())],
        help_text="场所ID",
    )
    types = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 10,
        required=True,
        help_text="配置数据",
    )
    # care = IntegerField(default=0, help_text="系数")
    # types = ChoiceField(
    #     choices=(
    #         "自定义",
    #         "新手关",
    #         "匹配赛",
    #         "排位赛",
    #         "战队赛",
    #         "大乱斗",
    #         "人机站",
    #         "统治战场",
    #         "大对决",
    #         "克隆赛",
    #         "无限火力",
    #         "镜像赛",
    #         "末日赛",
    #         "飞升赛",
    #         "六杀丛林",
    #         "魄罗乱斗",
    #     ),
    #     help_text="赛制名称",
    # )

    class Meta:
        model = GamePlaceconfLolTypes
        fields = ["id", "pid", "types"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


class GamePlaceconfLolGroupSerializer(serializers.ModelSerializer):
    """LOL大区配置"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolGroup.objects.all())],
        help_text="场所ID",
    )
    group = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 10,
        required=True,
        help_text="配置数据",
    )
    # care = IntegerField(default=0, help_text="系数")
    # group = ChoiceField(
    #     choices=(
    #         "艾欧尼亚",
    #         "班德尔城",
    #         "弗雷尔卓德",
    #         "裁决之地",
    #         "钢铁烈阳",
    #         "教育网专区",
    #         "卡拉曼达",
    #         "峡谷之巅",
    #         "比尔吉沃特",
    #         "德玛西亚",
    #         "巨神峰",
    #         "黑色玫瑰",
    #         "水晶之痕",
    #         "影流",
    #         "巨龙之巢",
    #         "祖安",
    #         "男爵领域",
    #         "皮尔特沃夫",
    #         "雷瑟守备",
    #         "暗影岛",
    #         "均衡教派",
    #         "守望之海",
    #         "皮城警备",
    #         "洛克萨斯",
    #         "战争学院",
    #         "无畏先锋",
    #         "怒瑞玛",
    #         "扭曲丛林",
    #         "征服之海",
    #     ),
    #     help_text="大区名称",
    # )

    class Meta:
        model = GamePlaceconfLolGroup
        fields = ["id", "pid", "group"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


class GamePlaceconfLolConsoleSerializer(serializers.ModelSerializer):
    """LOL终端系数配置"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolConsole.objects.all())],
        help_text="场所ID",
    )
    console = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 10,
        required=True,
        help_text="配置数据",
    )
    # care = IntegerField(default=0, help_text="系数")
    # console = CharField(allow_blank=True, allow_null=True, help_text="终端列表")
    # name = CharField(
    #     allow_blank=True,
    #     allow_null=True,
    #     max_length=255,
    #     required=False,
    #     help_text="名称",
    # )

    class Meta:
        model = GamePlaceconfLolConsole
        fields = ["id", "pid", "console"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


class GamePlaceconfLolDateSerializer(serializers.ModelSerializer):
    """无序列化"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(
        validators=[UniqueValidator(queryset=GamePlaceconfLolDate.objects.all())],
        help_text="场所ID",
    )
    name = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 20,
        required=True,
        help_text="配置数据",
    )
    # care = IntegerField(default=0, help_text="系数")
    # star = IntegerField(
    #     allow_null=True, max_value=23, min_value=0, required=True, help_text="时刻"
    # )
    # end = IntegerField(
    #     allow_null=True,
    #     max_value=2147483647,
    #     min_value=-2147483648,
    #     required=False,
    #     help_text="备用",
    # )
    # week = IntegerField(
    #     allow_null=True, max_value=6, min_value=0, required=True, help_text="星期"
    # )
    # name = CharField(
    #     allow_blank=True,
    #     allow_null=True,
    #     max_length=255,
    #     required=False,
    #     help_text="名称",
    # )

    class Meta:
        model = GamePlaceconfLolDate
        fields = ["id", "pid", "name"]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


class GamePlaceconfLolTasksSerializer(serializers.ModelSerializer):
    """无序列化"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(allow_null=True, required=True)
    name = CharField(allow_blank=True, allow_null=True, max_length=255, required=True)
    tasks = CharField(
        allow_blank=True,
        allow_null=True,
        required=False,
        style={"base_template": "textarea.html"},
    )

    class Meta:
        model = GamePlaceconfLolTasks
        fields = "__all__"
        validators = [
            UniqueTogetherValidator(
                queryset=GamePlaceconfLolTasks.objects.all(), fields=("pid", "name")
            )
        ]

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


# ===================================================================


class GameLolHonebaoLogsSerializer(serializers.ModelSerializer):
    """对局信息序列化"""

    id = IntegerField(read_only=True)
    parent = IntegerField(allow_null=True, required=False)
    unit_price = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    score = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)
    money = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)
    sortid = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    ename = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)
    cname = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)

    class Meta:
        model = GameLolHonebaoLogs
        fields = "__all__"


class GameLolHonebaoListSerializer(serializers.ModelSerializer):
    """游戏 lol战绩红包记录"""

    id = IntegerField(read_only=True)
    computername = ReadOnlyField()
    summonerid = ReadOnlyField()
    summonername = ReadOnlyField()
    area_cname = ReadOnlyField()
    tier = ReadOnlyField()
    cn_champion = ReadOnlyField()
    cn_gamemode = ReadOnlyField()
    cn_gametype = ReadOnlyField()
    win = ReadOnlyField()
    winpoint = ReadOnlyField()
    start_time = ReadOnlyField()
    stop_time = ReadOnlyField()
    lol_money = ReadOnlyField()
    firstwin = ReadOnlyField()
    seat_ratio = ReadOnlyField()
    tier_ratio = ReadOnlyField()
    time_ratio = ReadOnlyField()
    area_ratio = ReadOnlyField()
    type_ratio = ReadOnlyField()
    wx_money = ReadOnlyField()
    pid = ReadOnlyField()
    mid = ReadOnlyField()
    currentime = ReadOnlyField()
    code = ReadOnlyField()
    status = IntegerField(
        allow_null=True, max_value=1, min_value=0, help_text="0: 未支付 1: 已支付"
    )
    answer = IntegerField(allow_null=True, help_text="操作员ID")
    lasttime = DateTimeField(allow_null=True, required=False, help_text="兑换时间")

    data = SerializerMethodField()
    aname = SerializerMethodField()

    class Meta:
        model = GameLolHonebaoList
        fields = "__all__"

    def get_data(self, obj):
        r = GameLolHonebaoLogs.objects.filter(parent=obj.id)
        return GameLolHonebaoLogsSerializer(r, many=True).data

    def get_aname(self, obj):
        try:
            r = AllinpayStaffList.objects.get(id=obj.answer)
        except BaseException as err:
            return ""
        else:
            return r.basename


class GameLolEnvelopeSerializer(serializers.Serializer):
    """无序列化"""

    pid = IntegerField(allow_null=True, help_text="场所ID")
    code = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="识别码",
    )

    class Meta:
        fields = "__all__"

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不存在")
        return attr


# ======================================================================
class GameLolUseropenidListSerializer(serializers.ModelSerializer):
    """LOL账户绑定微信公众号"""

    class Meta:
        model = GameLolUseropenidList
        fields = "__all__"


class LoginGameLolUseropenidListSerializer(serializers.Serializer):
    """LOL账户绑定微信公众号"""

    userid = CharField(max_length=255, required=True, help_text="LOL游戏ID")

    class Meta:
        fields = "__all__"


class PostGameLolDataListSerializer(serializers.Serializer):
    """LOL游戏数据上传"""

    WBCode = CharField(allow_blank=True, allow_null=True, help_text="场所编码")
    name = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=True,
        help_text="计算机名",
    )
    data = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=1024 * 20,
        required=True,
        help_text="JSON数据",
    )

    class Meta:
        fields = "__all__"


# ==================================================
# ===========新 LOL 对局数据 上传====================
# ==================================================
class GameLolChessListSerializer(serializers.ModelSerializer):
    """LOL对局数据"""

    id = IntegerField(read_only=True)
    pid = IntegerField(allow_null=True, required=False)
    computer = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    puuid = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)
    money = IntegerField(allow_null=True, required=False)
    gameid = IntegerField(
        allow_null=True,
        required=False,
        validators=[UniqueValidator(queryset=GameLolChessList.objects.all())],
    )
    gamestarttime = DateTimeField(allow_null=True, required=False)
    gameendtime = DateTimeField(allow_null=True, required=False)
    gameduration = IntegerField(allow_null=True, required=False)
    summonerid = IntegerField(allow_null=True, required=False)
    summonername = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    summonerlevel = IntegerField(allow_null=True, required=False)
    championid = IntegerField(allow_null=True, required=False)
    championname = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    championsquareportraitpath = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    teamid = IntegerField(allow_null=True, required=False)
    championlevel = IntegerField(allow_null=True, required=False)
    firstwinbonus = IntegerField(allow_null=True, required=False)
    kills = IntegerField(allow_null=True, required=False)
    deaths = IntegerField(allow_null=True, required=False)
    assists = IntegerField(allow_null=True, required=False)
    largestkillingspree = IntegerField(allow_null=True, required=False)
    largestmultikill = IntegerField(allow_null=True, required=False)
    kills4 = IntegerField(allow_null=True, required=False)
    kills5 = IntegerField(allow_null=True, required=False)
    godlike = IntegerField(allow_null=True, required=False)
    turretkills = IntegerField(allow_null=True, required=False)
    inhibitorkills = IntegerField(allow_null=True, required=False)
    neutralminionskilled = IntegerField(allow_null=True, required=False)
    totalminionskilled = IntegerField(allow_null=True, required=False)
    goldearned = IntegerField(allow_null=True, required=False)
    goldspent = IntegerField(allow_null=True, required=False)
    wardskilled = IntegerField(allow_null=True, required=False)
    wardsplaced = IntegerField(allow_null=True, required=False)
    totaldamagedealt = IntegerField(allow_null=True, required=False)
    magicdamagedealt = IntegerField(allow_null=True, required=False)
    physicaldamagedealt = IntegerField(allow_null=True, required=False)
    totaldamagetaken = IntegerField(allow_null=True, required=False)
    totalheal = IntegerField(allow_null=True, required=False)
    firstbloodkill = IntegerField(allow_null=True, required=False)
    firsttowerkill = IntegerField(allow_null=True, required=False)
    team_firstbaron = IntegerField(allow_null=True, required=False)
    team_baronkills = IntegerField(allow_null=True, required=False)
    team_firstdargon = IntegerField(allow_null=True, required=False)
    team_dragonkills = IntegerField(allow_null=True, required=False)
    visionscore = IntegerField(allow_null=True, required=False)
    timeccingothers = IntegerField(allow_null=True, required=False)
    truedamagedealttochampions = IntegerField(allow_null=True, required=False)
    largestcriticalstrike = IntegerField(allow_null=True, required=False)
    damageselfmitigated = IntegerField(allow_null=True, required=False)
    damagedealttoturrets = IntegerField(allow_null=True, required=False)
    damagedealttoobjectives = IntegerField(allow_null=True, required=False)
    killcontribution = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    neutralminionskilledenemyjungle = IntegerField(allow_null=True, required=False)
    perk_hasg = IntegerField(allow_null=True, required=False)
    perk_yqsjq = IntegerField(allow_null=True, required=False)
    perk_xblr = IntegerField(allow_null=True, required=False)
    perk_xg = IntegerField(allow_null=True, required=False)
    perk_kx = IntegerField(allow_null=True, required=False)
    overallchallengelevel = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    platformid = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    platformname = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    gamemode = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    gamemodename = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    gametype = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    gametypename = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    mapid = IntegerField(allow_null=True, required=False)
    neutralminionskilledteamjungle = IntegerField(allow_null=True, required=False)
    truedamagedealt = IntegerField(allow_null=True, required=False)
    magicdamagedealttochampions = IntegerField(allow_null=True, required=False)
    physicaldamagedealttochampions = IntegerField(allow_null=True, required=False)
    totaldamagedealttochampions = IntegerField(allow_null=True, required=False)
    magicaldamagetaken = IntegerField(allow_null=True, required=False)
    physicaldamagetaken = IntegerField(allow_null=True, required=False)
    truedamagetaken = IntegerField(allow_null=True, required=False)
    team_kills = IntegerField(allow_null=True, required=False)
    team_deaths = IntegerField(allow_null=True, required=False)
    perk0 = IntegerField(allow_null=True, required=False)
    perk0name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk0var1 = IntegerField(allow_null=True, required=False)
    perk0var2 = IntegerField(allow_null=True, required=False)
    perk0var3 = IntegerField(allow_null=True, required=False)
    perk1 = IntegerField(allow_null=True, required=False)
    perk1name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk1var1 = IntegerField(allow_null=True, required=False)
    perk1var2 = IntegerField(allow_null=True, required=False)
    perk1var3 = IntegerField(allow_null=True, required=False)
    perk2 = IntegerField(allow_null=True, required=False)
    perk2name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk2var1 = IntegerField(allow_null=True, required=False)
    perk2var2 = IntegerField(allow_null=True, required=False)
    perk2var3 = IntegerField(allow_null=True, required=False)
    perk3 = IntegerField(allow_null=True, required=False)
    perk3name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk3var1 = IntegerField(allow_null=True, required=False)
    perk3var2 = IntegerField(allow_null=True, required=False)
    perk3var3 = IntegerField(allow_null=True, required=False)
    perk4 = IntegerField(allow_null=True, required=False)
    perk4name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk4var1 = IntegerField(allow_null=True, required=False)
    perk4var2 = IntegerField(allow_null=True, required=False)
    perk4var3 = IntegerField(allow_null=True, required=False)
    perk5 = IntegerField(allow_null=True, required=False)
    perk5name = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    perk5var1 = IntegerField(allow_null=True, required=False)
    perk5var2 = IntegerField(allow_null=True, required=False)
    perk5var3 = IntegerField(allow_null=True, required=False)
    queueid = IntegerField(allow_null=True, required=False)
    queuetype = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )

    class Meta:
        model = GameLolChessList
        fields = "__all__"


class GameLolRewardListSerializer(serializers.ModelSerializer):
    """LOL成就数据"""

    id = IntegerField(read_only=True)
    pid = IntegerField(allow_null=True, required=False)
    computer = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    puuid = CharField(allow_blank=True, allow_null=True, max_length=255, required=False)
    money = IntegerField(allow_null=True, required=False)
    gameid = IntegerField(
        allow_null=True,
        required=False,
        validators=[UniqueValidator(queryset=GameLolRewardList.objects.all())],
    )
    gamestarttime = DateTimeField(allow_null=True, required=False)
    gameendtime = DateTimeField(allow_null=True, required=False)
    gameduration = IntegerField(allow_null=True, required=False)
    summonerid = IntegerField(allow_null=True, required=False)
    summonername = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    summonerlevel = IntegerField(allow_null=True, required=False)
    championid = IntegerField(allow_null=True, required=False)
    championname = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    championsquareportraitpath = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    teamid = IntegerField(allow_null=True, required=False)
    championlevel = IntegerField(allow_null=True, required=False)
    firstwinbonus = IntegerField(allow_null=True, required=False)
    kills = IntegerField(allow_null=True, required=False)
    deaths = IntegerField(allow_null=True, required=False)
    assists = IntegerField(allow_null=True, required=False)
    largestkillingspree = IntegerField(allow_null=True, required=False)
    largestmultikill = IntegerField(allow_null=True, required=False)
    kills4 = IntegerField(allow_null=True, required=False)
    kills5 = IntegerField(allow_null=True, required=False)
    godlike = IntegerField(allow_null=True, required=False)
    turretkills = IntegerField(allow_null=True, required=False)
    inhibitorkills = IntegerField(allow_null=True, required=False)
    neutralminionskilled = IntegerField(allow_null=True, required=False)
    totalminionskilled = IntegerField(allow_null=True, required=False)
    goldearned = IntegerField(allow_null=True, required=False)
    goldspent = IntegerField(allow_null=True, required=False)
    wardskilled = IntegerField(allow_null=True, required=False)
    wardsplaced = IntegerField(allow_null=True, required=False)
    totaldamagedealt = IntegerField(allow_null=True, required=False)
    magicdamagedealt = IntegerField(allow_null=True, required=False)
    physicaldamagedealt = IntegerField(allow_null=True, required=False)
    totaldamagetaken = IntegerField(allow_null=True, required=False)
    totalheal = IntegerField(allow_null=True, required=False)
    firstbloodkill = IntegerField(allow_null=True, required=False)
    firsttowerkill = IntegerField(allow_null=True, required=False)
    team_firstbaron = IntegerField(allow_null=True, required=False)
    team_baronkills = IntegerField(allow_null=True, required=False)
    team_firstdargon = IntegerField(allow_null=True, required=False)
    team_dragonkills = IntegerField(allow_null=True, required=False)
    team_firstancientdragon = IntegerField(allow_null=True, required=False)
    team_ancientdragonkills = IntegerField(allow_null=True, required=False)
    team_firstinhibitor = IntegerField(allow_null=True, required=False)
    team_inhibitorkills = IntegerField(allow_null=True, required=False)
    team_towerkills = IntegerField(allow_null=True, required=False)
    team_riftheraldkills = IntegerField(allow_null=True, required=False)
    visionscore = IntegerField(allow_null=True, required=False)
    timeccingothers = IntegerField(allow_null=True, required=False)
    truedamagedealttochampions = IntegerField(allow_null=True, required=False)
    largestcriticalstrike = IntegerField(allow_null=True, required=False)
    damageselfmitigated = IntegerField(allow_null=True, required=False)
    damagedealttoturrets = IntegerField(allow_null=True, required=False)
    damagedealttoobjectives = IntegerField(allow_null=True, required=False)
    killcontribution = IntegerField(allow_null=True, required=False)
    neutralminionskilledenemyjungle = IntegerField(allow_null=True, required=False)
    perk_hasg = IntegerField(allow_null=True, required=False)
    perk_yqsjq = IntegerField(allow_null=True, required=False)
    perk_xblr = IntegerField(allow_null=True, required=False)
    perk_xg = IntegerField(allow_null=True, required=False)
    perk_kx = IntegerField(allow_null=True, required=False)

    class Meta:
        model = GameLolRewardList
        fields = "__all__"


class LOLResDataUploadSerializer(serializers.Serializer):
    """LOL数据上传序列化"""

    pid = IntegerField(allow_null=True)
    computer = CharField(allow_blank=True, allow_null=True, max_length=255)
    puuid = CharField(allow_blank=True, allow_null=True, max_length=255)
    money = IntegerField(allow_null=True, default=0)
    gameId = IntegerField(allow_null=True)
    gameStartTime = DateTimeField(allow_null=True, required=False)
    gameEndTime = DateTimeField(allow_null=True, required=False)
    gameDuration = IntegerField(allow_null=True, required=False)
    summonerId = IntegerField(allow_null=True, required=False)
    summonerName = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    summonerLevel = IntegerField(allow_null=True, required=False)
    championId = IntegerField(allow_null=True, required=False)
    championName = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    championSquarePortraitPath = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )
    teamId = IntegerField(allow_null=True, required=False)

    militaryExplotis = JSONField(allow_null=True, required=False)
    reward = JSONField(allow_null=True, required=False)

    class Meta:
        fields = "__all__"

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不可用")
        return attr


class GameLolPayactListSerializer(serializers.ModelSerializer):
    """无序列化"""

    id = IntegerField(label="ID", read_only=True)
    pid = IntegerField(allow_null=True, required=False)
    gameid = IntegerField(
        allow_null=True,
        required=False,
        validators=[UniqueValidator(queryset=GameLolPayactList.objects.all())],
    )
    openid = CharField(
        allow_blank=True, allow_null=True, max_length=255, required=False
    )

    money = IntegerField(allow_null=True, required=False)
    payact = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="支付方式",
    )
    bem = CharField(
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
        help_text="备注信息",
    )
    creatime = DateTimeField(
        read_only=True, allow_null=True, required=False, help_text="支付时间"
    )

    creatday = DateField(
        read_only=True, allow_null=True, required=False, help_text="创建日期"
    )
    superid = IntegerField(read_only=True, allow_null=True, required=False)
    supername = CharField(
        read_only=True,
        allow_blank=True,
        allow_null=True,
        max_length=255,
        required=False,
    )

    class Meta:
        model = GameLolPayactList
        fields = "__all__"

    def validate_pid(self, attr):
        try:
            r = AllinpayPlaceList.objects.get(id=attr, status=1)
        except BaseException as err:
            raise serializers.ValidationError("场所对象不可用")
        return attr

    def validate(self, attrs):
        attrs = dict(attrs)
        if not attrs.get("money"):
            raise serializers.ValidationError("金额不能为空")
        try:
            r = GameLolRewardListSerializer.objects.get(gameid=attrs.get("gameid"))
            u = GameLolUseropenidList.objects.get(userid=r.puuid)
        except GameLolRewardList.DoesNotExist as err:
            raise serializers.ValidationError("对局成就不可用")
        except GameLolUseropenidList.DoesNotExist as err:
            raise serializers.ValidationError("用户openid不可用")
        except BaseException as err:
            raise serializers.ValidationError("其他异常")
        else:
            attrs["openid"] = u.openid
            if not attrs.get("money") == r.money:
                raise serializers.ValidationError("金额与奖励金额不一致")
        return attrs


# print(repr(GameLolPayactListSerializer()))
